define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'baoxiao/index' + location.search,
                    add_url: 'baoxiao/add',
                    edit_url: 'baoxiao/edit',
                    del_url: 'baoxiao/del',
                    multi_url: 'baoxiao/multi',
                    import_url: 'baoxiao/import',
                    table: 'baoxiao',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'stand_id', title: __('Stand_id')},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'comrepair_id', title: __('Comrepair_id')},
                        {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE',formatter: function(value, row){
                            var type_name = value == null ? '' : value;
                            return type_name;
                        }},
                        {field: 'admin.device_no', title: __('Admin.device_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,formatter: function(value, row){
                                var type_name = value == null ? '' : value;
                                return type_name;
                            }},
                        {field: 'stand.name', title: __('Stand.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,formatter: function(value, row){
                                var type_name = value == null ? '' : value;
                                return type_name;
                            }},
                        {field: 'comrepair.name', title: __('Comrepair.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,formatter: function(value, row){
                                var type_name = value == null ? '' : value;
                                return type_name;
                            }},
                        {field: 'product', title: __('Product'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'num', title: __('Num')},
                        {field: 'unit_price', title: __('Unit_price'), operate:'BETWEEN'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'cj_images', title: __('Cj_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'content', title: __('Content'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_pay', title: __('Is_pay'), searchList: {"0":__('Is_pay 0'),"1":__('Is_pay 1')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
